import { useMemo } from 'react'

function useData(data, indexToFieldArray) {
  const dataSource = useMemo(
    () =>
      data.map((item, index) => {
        const _item = { key: index }
        for (const [i, v] of item.entries()) {
          _item[indexToFieldArray[i]] = v
        }
        return _item
      }),
    [data, indexToFieldArray]
  )

  return dataSource
}

export default useData
